#include "Input.h"
/*most of the stuff in here is to help my dissertation project
by faking key presses and mouse downs so that ordinary mouse and key board
already being used in an app can be switched straight to wii controls*/
namespace XF
{
	void Input::FakeKeyPress( int key )
	{
		mKeyBoard.mCurrKeys[key] = true;
		mKeyBoard.mOldKeys[key]  =false;
	}

	void Input::FakeKeyDown( int key )
	{
		mKeyBoard.mCurrKeys[key] = mKeyBoard.mOldKeys[key]  =true;
	}

	void Input::FakeKeyUp( int key )
	{
		mKeyBoard.mCurrKeys[key] = mKeyBoard.mOldKeys[key]  =false;
	}

	void Input::FakeKeyRelease( int key )
	{
		mKeyBoard.mCurrKeys[key] = false;
		mKeyBoard.mOldKeys[key]  =true;
	}

	void Input::FakeMouseButtonPress( int button )
	{
		mMouse.Buttons[button] = true;
		mMouse.OldButtons[button] = false;
	}

	void Input::FakeMouseButtonDown( int button )
	{
		mMouse.Buttons[button] = mMouse.OldButtons[button]  =true;
	}

	void Input::FakeMouseButtonUp( int button )
	{
		mMouse.Buttons[button] = mMouse.OldButtons[button]  =false;
	}		

	void Input::FakeMouseButtonRelease( int button )
	{
		mMouse.Buttons[button] = false;
		mMouse.OldButtons[button] = true;
	}

	void Input::SetMouseX(int x)
	{
		SetCursorPos(x,GetMouseY());	
	}

	void Input::SetMouseY(int y)
	{
		SetCursorPos(GetMouseX(),y);
	}
	void Input::SetMouseCursor(int x, int y)
	{
		SetCursorPos(x,y);
	}

	bool Input::IsMouseMoving( DWORD movementType  )
	{
		if((movementType & MovingTypes::mvLeft) == MovingTypes::mvLeft)
		{
			if(mMouse.X < mMouse.OldX)
			{
				return true;
			}
		}
		if((movementType & MovingTypes::mvRight) == MovingTypes::mvRight)
		{
			if(mMouse.X > mMouse.OldX)
			{
				return true;
			}
		}
		if((movementType & MovingTypes::mvDown) == MovingTypes::mvDown)
		{
			if(mMouse.Y < mMouse.OldY)return true;
		}
		if((movementType & MovingTypes::mvUp) == MovingTypes::mvUp)
		{
			if(mMouse.Y > mMouse.OldY)return true;
		}
		return false;
	}


	void Input::Update()
	{	
		//copy current keys into old keys
		memcpy(mKeyBoard.mOldKeys, mKeyBoard.mCurrKeys, sizeof(bool)*NUM_KEYS);
		//copy current keys into old keys
		memcpy(mMouse.OldButtons, mMouse.Buttons, sizeof(bool)*3);

		mMouse.OldX = mMouse.X;
		mMouse.OldY = mMouse.Y;

		OnUpdate();
	}
}